package com.dstz.bpm.engine.plugin.context;

import com.alibaba.fastjson.JSON;
import com.dstz.base.core.util.StringUtil;
import com.dstz.bpm.api.engine.plugin.context.BpmPluginContext;
import com.dstz.bpm.api.engine.plugin.def.BpmPluginDef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractBpmPluginContext<T extends BpmPluginDef> implements BpmPluginContext<T> {
   private static final long serialVersionUID = 1L;
   protected Logger LOG = LoggerFactory.getLogger(this.getClass());
   private T bW;
   protected int bX = 100;

   public T getBpmPluginDef() {
      return this.bW;
   }

   public void setBpmPluginDef(T bpmPluginDef) {
      this.bW = bpmPluginDef;
   }

   protected abstract T parseFromJson(JSON var1);

   public JSON getJson() {
      return (JSON)JSON.toJSON(this.bW);
   }

   public T parse(JSON json) {
      T def = this.parseFromJson(json);
      this.setBpmPluginDef(def);
      return this.bW;
   }

   public T parse(String json) {
      if (StringUtil.isEmpty(json)) {
         return null;
      } else {
         JSON j = (JSON)JSON.parse(json);
         return this.parse(j);
      }
   }

   public String getType() {
      return StringUtil.lowerFirst(this.getClass().getSimpleName().replaceAll("PluginContext", ""));
   }

   public String persistnce(String defId) {
      String msg = null;
      if (this.getJson() == null) {
         msg = "清空改插件";
      }

      return msg;
   }

   public Integer getSn() {
      return this.bX;
   }

   public int compareTo(BpmPluginContext pluginContext) {
      if (this.bX == pluginContext.getSn()) {
         return 0;
      } else {
         return this.bX > pluginContext.getSn() ? 1 : 0;
      }
   }
}
